$(function() {  
    FastClick.attach(document.body);  
});

//更多
var inde = 1;
$(document).click(function(){
	inde++;
	if(inde%2!=0){
	  	$('.more').css({display:'none'});	
	 }
});
$('.headerR img').click(function(){
	  if(inde%2!=0){
	  	$('.more').css({display:'block'});  	
	  }
	  
});
/*var index = 0;
//足迹
$('.jilu').click(function(){
   var textC=$(this).text();
	if(textC=='编辑'){
		$(this).text('完成');
		$('.evaluateGoodsIO').css({display:'block'});
		$('.footprint').css({marginBottom:'9.9rem'});
		$('.footprint li img:nth-child(3)').css({marginLeft:'11.5%'});
		$('.footprint li div:nth-child(4)').css({marginLeft:'55.5%'});
        $('.footprintE').css({display:'block'});
        $('.footprint li input').css({display:'block'});
        $('.footprintE a:nth-child(5)').click(function(){
         $('.jilu').text('编辑');	
		$('.evaluateGoodsIO').css({display:'none'})
		$('.footprint li img:nth-child(3)').css({marginLeft:'0'});
		$('.footprint li div:nth-child(4)').css({marginLeft:'38%'});
		 $('.footprintE').css({display:'none'});
        });
		
	}else{
		$(this).text('编辑');
		$('.evaluateGoodsIO').css({display:'none'})
		$('.footprint li img:nth-child(3)').css({marginLeft:'0'});
		$('.footprint li div:nth-child(4)').css({marginLeft:'44.3%'});
		 $('.footprintE').css({display:'none'});
		
	}
	
});
*/
var index = 0;
//收藏
$('.jilu').click(function(){
	var textC=$(this).text();
	if(textC=='编辑'){
		$(this).text('完成');
	    $('.evaluateGoodsIO').css({display:'block'});
	    $('.footprintE').css({display:'block'});
	    $('.footprintE input').css({display:'block'});
	    $('.footprintE a:nth-child(5)').click(function(){
	    $('.jilu').text('编辑');	
	    $('.footprintE').css({display:'none'});
	  });
	}else{
		 $(this).text('编辑');
		 $('.goodss .box').prop('checked', false);
		 $('.jiesuan img').attr('src',rootPath+'/image/yuan1.png');
		 $('.footprintE input ').prop('checked', false);
		 $('.evaluateGoodsIO').attr('src',rootPath+'/image/yuan1.png');
		 $('.evaluateGoodsIO').css({display:'none'});
		 $('.footprintE').css({display:'none'});
		 };
	
});
var srcPath = rootPath+'/image/yuan2.png'

/**  全选以及全部不选操作*/
var check = document.querySelectorAll('.check');
var checkAllcount= document.querySelector(".checkAll");
var imgss = document.querySelectorAll('.evaluateGoodsIO')
var del = document.querySelectorAll('.footprintE a:nth-child(4)')[0];
var liss= document.querySelectorAll('.footprint li');


$('.footprintE input').click(function(){
	var check=$('.footprint .check').prop('checked', this.checked);
	/** 全选全不选*/
	if(this.checked==true){
	    $('.jiesuan img').attr('src',rootPath+'/image/yuan2.png');
		$('.evaluateGoodsIO').attr('src',rootPath+'/image/yuan2.png');
		  
	}else if(this.checked!=true){
	    $('.jiesuan img').attr('src',rootPath+'/image/yuan1.png');
		$('.evaluateGoodsIO').attr('src',rootPath+'/image/yuan1.png');
	}
});	
$(document).on("click",".footprint .check",function(){
	console.log($('.footprintE input'));	
	//必要时更新全选按钮
	var allCheckBoxCount = $('.footprint .check').length;
	var checkedCount = $('.footprint .check:checked').length;
	var $checked=checkedCount==allCheckBoxCount;
	if($checked){	
		$('.jiesuan img').attr('src',rootPath+'/image/yuan2.png');	//全选选中
		$('.footprintE input ').prop('checked', true);	//全选选中
	}else {
		$('.jiesuan img').attr('src',rootPath+'/image/yuan1.png');	//全选不选中
		$('.footprintE input ').prop('checked', false);	//全选不选中
	}
	/**check单选框*/
    if($(this).prop('checked')){
    	//alert($(this).prop('checked'));
    	$(this).prop('checked',true);
		$(this).next().attr('src',rootPath+'/image/yuan2.png');
	}else{
		$(this).prop('checked',false);
		$(this).next().attr('src',rootPath+'/image/yuan1.png');
	} 
		
});

$('.jiesuan a:nth-child(4)').click(function(){
    $('.footprint').remove();
   /* $('.footprintE').css({display:'none'});*/
    $('.jilu').text('编辑');
});


/***删除足迹信息*****/
function deleteFootprint(){
	var chk_value=[];
	var arrUrl = $(".evaluateGoods>li");
	$.each(arrUrl,function(){
		var src = $(this).find(".evaluateGoodsIO").attr("src")
		var val = $(this).find(".check").val();
		if(srcPath == src){
			chk_value.push(val);	
		}
	});
	if(chk_value.length<1){
		alert("请选择要删除的商品！");
		return false;
	}
	if(confirm("确定要删除吗?")){
		var chk_value=[];
		var arrUrl = $(".footprint >li");
		$.each(arrUrl,function(){
			var src = $(this).find(".evaluateGoodsIO").attr("src")
			var val = $(this).find(".check").val();
			if(srcPath == src){
				chk_value.push(val);
			}
		});
		$.ajax({
			url : rootPath+"/consultComment/deleteFootprint",
			type : "POST",
			data : {"id":""+chk_value+""},
			async: false,
			success: function(data,status){
				if(data == "success"){console.log("删除成功！");window.location.reload(); }else if(data == 'null'){}else{alert("删除失败!")}
			},
			error: function(xhr,status,e){
				alert("服务器出了问题，请检查！"+e);
			}	
		});
	}else{
		return false;
	}
}


var currentPage = 2;
/**足迹分页****/
function clickRefresh(){
	// 加载数据
    $.ajax({
        type: 'POST',
        url : rootPath+"/consultComment/queryConsult.do",
        data : {"currPage":currentPage,"type":3},
      	async : false,
        success: function(data,status){
        	currentPage =data.currentPage;
        	currentPage++;
         	var resultList = data.resultList;
         	var totalRecords = data.totalRecords; //总条数
        	if(resultList!=null && resultList.length>0){
    			var optionHtml = '';
    			$.each(resultList,function(i,result){
					optionHtml+="<li> "
						+" <input type='checkbox' name='checkName' value='"+result.id+"'/> "
						+" <img src='"+rootPath+"/image/yuan1.png' alt='' class='evaluateGoodsIO'/> "
						+" <img src='"+rootPath+"/image/pic184.png' alt='' class='evaluateGoodsI'/> "
						+" <div class='evaluateGoodsW'> "
						+" <p class='wordes moreWord'>"+result.goodsName+"</p> "
						+" <p class='prices'> "
						+" <b>¥ "+result.marketPrice+"</b> "
			//			+" <a href='javascript:void(0);'>看相似</a> "
						+" </p> "
						+" </div> "
						+" </li>";
				});
        	}else{
        		$(".pageRefresh").text("数据加载完毕！！！")
        		$(".pageRefresh").removeAttr("onclick");  //移除事件
        	}	
        	$(".pageRefresh").before(optionHtml);
       	},
        error: function(xhr, type){
            alert('Ajax error!');
        }
    });
}

